<template>
    <div>
      <VitaeList 
          :vitaeData="vitaeData"
          @updataVitae="updataVitae"
          @delVitae="delVitae"
          ></VitaeList>
      <div class="submit">
        <el-button 
        @click="addVitae" 
        type="primary" 
        round size="large">新建简历</el-button>
      </div>
    </div>
  </template>
<script setup>
import { inject, watch , ref } from 'vue';
import { useRouter } from 'vue-router'
import checkLoginStatus from '@/hooks/checkLoginStatus.js'
import login from '@/hooks/login.js'
import VitaeList from '@/components/vitaeList.vue'
const $axios = inject('$axios')
const $root = inject('$root')
const router = useRouter()

let vitaeData = ref([])
// 获取简历列表
const getVitaeData = () => {
  $axios.get($root+`/curri/`).then(r=>{
    vitaeData.value = r.data.data
  })
}

const updataVitae = (rid)=>{
    router.push(`/addvitae/${rid}`)
}

const delVitae = (rid)=>{
  $axios.post($root+`/curri/delete/${rid}/`).then(r=>{
    if(r.data.code == 200){
      getVitaeData()
    }
  })
}


const addVitae = ()=>{
    router.push('/addvitae')
}


watch(() => router.currentRoute.value.name, (name) => {
  if (name == "vitae") {
    checkLoginStatus(getVitaeData, login)
  }
}, { immediate: true, deep: true })

</script>